[#ftl]
[@bootstrapChains "Step2/3 Initializing Event"]

agile.singoton("agile.EventMetadata",agile.XStyleMetadata,{
	editorClass:"agile.EventEditor"
	,metadataCategory:"event"
	[#assign templateString]<div><div data-dojo-type="agile.EventEditor" class="xeditor" data-dojo-props="name:'{name}',args:'{args}',remark:'{remark}'"></div></div>[/#assign]
 	,templateString:"${templateString?js_string}"
 	
	,onValueChange:function(widget,name,value){
		widget.metadata("event."+name,value);
	}
 	,serialize:function(event,actions,sourceType){
 		//onChange,"1:w14438001782380:Hello World", dojo
		var events = "" , template = "";
		//action code:"1.Show dialog,2.Hide dialog,3.Show panel,4.Hide panel,5.Open page in new window,6.Other"
		array.forEach(actions.split(";"),function(action){
			var v = action.split(":"), actionCode = v[0],target = v[1];

			switch(actionCode){
				case "1"://show dialog
				case "2"://hide dialog
					[#assign template][#compress][#noparse]
					<script type="dojo/connect" event="${event}">					
						var dialog = registry.byId("${target}"); 
						if(dialog){
							dialog.${func}();
						}
					</script>
					[/#noparse][/#compress][/#assign]
					
					var func = {"1":"show","2":"hide"}[actionCode];
					events += lang.replace("${template?replace("\n","")?js_string}",{event:event,target:target,func:func},/\$\{([^\}]+)\}/g);
										
					break;
				case "3"://show panel					
				case "4"://hide panel
					[#assign template][#compress][#noparse]
					<script type="dojo/connect" event="${event}">					
						var panel = registry.byId("${target}"); 
						if(panel){
							style.set(panel.domNode,"display","${display}");
						}
					</script>
					[/#noparse][/#compress][/#assign]
					
					var display = {"3":"block","4":"none"}[actionCode];
					events += lang.replace("${template?replace("\n","")?js_string}",{event:event,target:target,display:display},/\$\{([^\}]+)\}/g);
					
					break;
				case "5"://open window
					template = '<'+'script type="dojo/connect" event="{event}">window.open("{target}");<' + '/script>';
					events += lang.replace(template,{event:event,target:target});
					break;
				case "6":
					break;
				case "7":
					break;					
			}	
			
		});
		
		
		
		return events;
 	}
});

[/@]